package com.huage_02.lesson_01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo {
    public static void main(String[] args) throws Exception {

        //注册驱动
        //ClassNotFoundException: com.mysql.cj.jdbc.Driver 给对应模块的lib添加jar
        //Loading class `com.mysql.jdbc.Driver'. This is deprecated. 已被弃用
        // The new driver class is `com.mysql.cj.jdbc.Driver'.
        Class.forName("com.mysql.cj.jdbc.Driver");  //可以省略
        //创建连接
        //The server time zone value '�й���׼ʱ��' is unrecognized
        //添加时区 jdbc:mysql://localhost:3306/test?serverTimezone=GMT
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=GMT", "root", "root");
        //编写sql语句
        String sql = "update student_info set sex = '男' where name = '李明'";
        //获取执行sql语句的对象
        Statement stmt = conn.createStatement();
        //执行sql
        int i = stmt.executeUpdate(sql);
        System.out.println("i = " + i);
        //关闭资源
        stmt.close();
        conn.close();
    }
}
